
package com.example.hotel_lxy.utils;

import android.annotation.SuppressLint;
import android.content.Context;
import android.util.Log;
import android.widget.TextView;

import com.example.hotel_lxy.R;
import com.example.hotel_lxy.bean.DataIndexBean;
import com.github.mikephil.charting.components.MarkerView;
import com.github.mikephil.charting.data.CandleEntry;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.highlight.Highlight;
import com.github.mikephil.charting.utils.MPPointF;
import com.github.mikephil.charting.utils.Utils;

import java.math.BigDecimal;
import java.util.List;


/**
 * Custom implementation of the MarkerView.
 *
 * @author Philipp Jahoda
 */
@SuppressLint("ViewConstructor")
public class MyMarkerView extends MarkerView {

    private final TextView tvContent,num;
    private TextView mTvMonth;
    private  List<DataIndexBean.DataBean.TrendBean> trend;
    public MyMarkerView(Context context, int layoutResource, List<DataIndexBean.DataBean.TrendBean> trend) {
        super(context, layoutResource);
        mTvMonth = findViewById(R.id.tv_chart_month);
        num=findViewById(R.id.num);
        tvContent = findViewById(R.id.content);
       this.trend=trend;
    }

    // runs every time the MarkerView is redrawn, can be used to update the
    // content (user-interface)
    @Override
    public void refreshContent(Entry e, Highlight highlight) {
        try {
            //收入
            String s=e.getY()+"".replace(".0","");
            String replace = s.replace(".0", "");
            String m=  (int)e.getX() + 1+"";
            mTvMonth.setText(String.valueOf((int) e.getX() + 1).concat("月"));
            for (int i = 0; i < trend.size(); i++) {
                if(m.equals(""+trend.get(i).getMonth())){
                    num.setText("预定数："+trend.get(i).getNum()+"单");
                    tvContent.setText("结单数："+trend.get(i).getCounum()+"单");
                    break;
                }
            }
        } catch (Exception e1) {
            e1.printStackTrace();
        }
        super.refreshContent(e, highlight);
    }

    @Override
    public MPPointF getOffset() {
        return new MPPointF(-(getWidth() / 2), -getHeight());
    }

}
